﻿namespace GameLib.Games.Components
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    public class ModDependencyResolver<T> : IModMatcherResolver<T> where T : IMod
    {
        public IList<MatcherStruct<T>> Resolve(IModMatcher matcher, IModCollection<T> mods)
        {
            IList<MatcherStruct<T>> result = new List<MatcherStruct<T>>();
            if (!matcher.Matches(mods))
            {
                bool matched = false;
                foreach (T mod in matcher.Match(matcher.Owner.Owner.GetInstalledMods<T>()))
                {
                    result.Add(new MatcherStruct<T>(matcher, mod));
                    matched = true;
                }
                if (!matched)
                {
                    result.Add(new MatcherStruct<T>(matcher));
                }
            }
            return result;
        }
    }
}
